package cn.itlaobing.web.interceptor;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created by Berlin-IOU on 2017/12/11.
 */
public class AuthenticationInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession httpSession=request.getSession();
        if (httpSession.getAttribute("CURRENT_USER")==null){
            httpSession.setAttribute("BACK_URL",request.getRequestURI());
            response.sendRedirect(request.getContextPath()+"/signin.jsp");
            return false;
        }
        return true;
    }
}
